package com.copa.l2032;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author copa
 * @createDate 2022-12-29 12:21
 * @function set判断法
 */
public class Test1 {

    public List<Integer> twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) {
        List<Integer> resultList = new ArrayList<>();
        Set<Integer> numSet1 = new HashSet<>();
        for (int i : nums1) {
            numSet1.add(i);
        }
        Set<Integer> numSet2 = new HashSet<>();
        for (int i : nums2) {
            numSet2.add(i);
        }
        Set<Integer> numSet3 = new HashSet<>();
        for (int i : nums3) {
            numSet3.add(i);
        }
        Set<Integer> numSet = new HashSet<>();
        for (Integer num1 : numSet1) {
            if (!numSet.contains(num1)) {
                numSet.add(num1);
                if (numSet2.contains(num1)) {
                    resultList.add(num1);
                    continue;
                }
                if (numSet3.contains(num1)) {
                    resultList.add(num1);
                }
            }
        }
        for (Integer num2 : numSet2) {
            if (!numSet.contains(num2)) {
                numSet.add(num2);
                if (numSet3.contains(num2)) {
                    resultList.add(num2);
                }
            }
        }
        return resultList;
    }

    public static void main(String[] args) {
        int[] num1 = {3,1};
        int[] num2 = {2,3};
        int[] num3 = {1,2};
        List<Integer> list = new Test1().twoOutOfThree(num1, num2, num3);
        list.forEach(System.out::println);
    }
}
